const { htmlToDocx } = require('../dist/lib/index.js');

async function testTransformation() {
  const html = `
    <img style="display: inline-block; height: 20px;" src="" width="100%" />
  `;

  try {
    console.log('开始转换 HTML 到 DOCX...');
    const result = await htmlToDocx(html);
    console.log('转换成功！');
    console.log('警告信息:', result.warnings);

    // 检查文档内容
    const documentWrapper = result.document.documentWrapper;
    const document = documentWrapper.document;
    const body = document.body;

    body.root.forEach((item) => {
      if (item.constructor.name === 'Paragraph') {
        item.root.forEach((rootItem) => {
          if (rootItem.constructor.name === 'ImageRun') {
            console.log('找到图片运行！');
            console.log('图片运行属性:', Object.keys(rootItem));

            // 检查 transformation 属性
            if (rootItem.transformation) {
              console.log('图片变换:', rootItem.transformation);
              console.log('变换属性:', Object.keys(rootItem.transformation));

              if (rootItem.transformation.width) {
                console.log('图片宽度:', rootItem.transformation.width);
              }
              if (rootItem.transformation.height) {
                console.log('图片高度:', rootItem.transformation.height);
              }
            }

            // 检查 root 中的尺寸信息
            if (rootItem.root) {
              rootItem.root.forEach((rootChild) => {
                if (rootChild.constructor.name === 'Drawing') {
                  console.log('Drawing 元素 root 长度:', rootChild.root.length);
                  rootChild.root.forEach((drawingChild) => {
                    if (drawingChild.constructor.name === 'BuilderElement') {
                      drawingChild.root.forEach((builderChild) => {
                        if (builderChild.constructor.name === 'DocProperties') {
                          console.log('DocProperties 属性:', Object.keys(builderChild));
                          if (builderChild.root) {
                            builderChild.root.forEach((docProp) => {
                              console.log('DocProperties 子元素:', docProp.constructor.name);
                              console.log('DocProperties 子元素属性:', Object.keys(docProp));
                            });
                          }
                        }
                      });
                    }
                  });
                }
              });
            }
          }
        });
      }
    });
  } catch (error) {
    console.error('转换失败:', error);
  }
}

testTransformation();
